/* eslint-disable */
import * as _m0 from "protobufjs/minimal";

export const protobufPackage = "";

/** 终端信息 */
export interface PBDeviceInfo {
  /** 终端序列号 */
  terminalSn: string;
  /** 日志级别 */
  logLevel: number;
}

/** 客户端网络配置信息 */
export interface PBNetInfo {
  /** mac地址 */
  macAddr: Uint8Array;
  /** 是否使用dhcp */
  useDhcp: boolean;
  /** ip地址 */
  ip: number;
  /** 网关地址 */
  gateway: number;
  /** 子网掩码 */
  subnetMask: number;
  /** dns地址 */
  dns: number;
}

/** 服务端配置信息 */
export interface PBServerInfo {
  /** 服务器主机名 */
  hostname: string;
  /** 服务器端口号，没有uint16类型，使用uint32代替 */
  port: number;
}

/** 服务端配置信息 */
export interface PBTerninalConfigration {
  /** 设备信息 */
  deviceInfo:
    | PBDeviceInfo
    | undefined;
  /** 网络信息 */
  netInfo:
    | PBNetInfo
    | undefined;
  /** 服务器信息 */
  serverInfo: PBServerInfo | undefined;
}

function createBasePBDeviceInfo(): PBDeviceInfo {
  return { terminalSn: "", logLevel: 0 };
}

export const PBDeviceInfo = {
  encode(message: PBDeviceInfo, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
    if (message.terminalSn !== "") {
      writer.uint32(10).string(message.terminalSn);
    }
    if (message.logLevel !== 0) {
      writer.uint32(16).uint32(message.logLevel);
    }
    return writer;
  },

  decode(input: _m0.Reader | Uint8Array, length?: number): PBDeviceInfo {
    const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = createBasePBDeviceInfo();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          if (tag !== 10) {
            break;
          }

          message.terminalSn = reader.string();
          continue;
        case 2:
          if (tag !== 16) {
            break;
          }

          message.logLevel = reader.uint32();
          continue;
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skipType(tag & 7);
    }
    return message;
  },

  fromJSON(object: any): PBDeviceInfo {
    return {
      terminalSn: isSet(object.terminalSn) ? globalThis.String(object.terminalSn) : "",
      logLevel: isSet(object.logLevel) ? globalThis.Number(object.logLevel) : 0,
    };
  },

  toJSON(message: PBDeviceInfo): unknown {
    const obj: any = {};
    if (message.terminalSn !== "") {
      obj.terminalSn = message.terminalSn;
    }
    if (message.logLevel !== 0) {
      obj.logLevel = Math.round(message.logLevel);
    }
    return obj;
  },

  create<I extends Exact<DeepPartial<PBDeviceInfo>, I>>(base?: I): PBDeviceInfo {
    return PBDeviceInfo.fromPartial(base ?? ({} as any));
  },
  fromPartial<I extends Exact<DeepPartial<PBDeviceInfo>, I>>(object: I): PBDeviceInfo {
    const message = createBasePBDeviceInfo();
    message.terminalSn = object.terminalSn ?? "";
    message.logLevel = object.logLevel ?? 0;
    return message;
  },
};

function createBasePBNetInfo(): PBNetInfo {
  return { macAddr: new Uint8Array(0), useDhcp: false, ip: 0, gateway: 0, subnetMask: 0, dns: 0 };
}

export const PBNetInfo = {
  encode(message: PBNetInfo, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
    if (message.macAddr.length !== 0) {
      writer.uint32(10).bytes(message.macAddr);
    }
    if (message.useDhcp === true) {
      writer.uint32(16).bool(message.useDhcp);
    }
    if (message.ip !== 0) {
      writer.uint32(24).uint32(message.ip);
    }
    if (message.gateway !== 0) {
      writer.uint32(32).uint32(message.gateway);
    }
    if (message.subnetMask !== 0) {
      writer.uint32(40).uint32(message.subnetMask);
    }
    if (message.dns !== 0) {
      writer.uint32(48).uint32(message.dns);
    }
    return writer;
  },

  decode(input: _m0.Reader | Uint8Array, length?: number): PBNetInfo {
    const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = createBasePBNetInfo();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          if (tag !== 10) {
            break;
          }

          message.macAddr = reader.bytes();
          continue;
        case 2:
          if (tag !== 16) {
            break;
          }

          message.useDhcp = reader.bool();
          continue;
        case 3:
          if (tag !== 24) {
            break;
          }

          message.ip = reader.uint32();
          continue;
        case 4:
          if (tag !== 32) {
            break;
          }

          message.gateway = reader.uint32();
          continue;
        case 5:
          if (tag !== 40) {
            break;
          }

          message.subnetMask = reader.uint32();
          continue;
        case 6:
          if (tag !== 48) {
            break;
          }

          message.dns = reader.uint32();
          continue;
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skipType(tag & 7);
    }
    return message;
  },

  fromJSON(object: any): PBNetInfo {
    return {
      macAddr: isSet(object.macAddr) ? bytesFromBase64(object.macAddr) : new Uint8Array(0),
      useDhcp: isSet(object.useDhcp) ? globalThis.Boolean(object.useDhcp) : false,
      ip: isSet(object.ip) ? globalThis.Number(object.ip) : 0,
      gateway: isSet(object.gateway) ? globalThis.Number(object.gateway) : 0,
      subnetMask: isSet(object.subnetMask) ? globalThis.Number(object.subnetMask) : 0,
      dns: isSet(object.dns) ? globalThis.Number(object.dns) : 0,
    };
  },

  toJSON(message: PBNetInfo): unknown {
    const obj: any = {};
    if (message.macAddr.length !== 0) {
      obj.macAddr = base64FromBytes(message.macAddr);
    }
    if (message.useDhcp === true) {
      obj.useDhcp = message.useDhcp;
    }
    if (message.ip !== 0) {
      obj.ip = Math.round(message.ip);
    }
    if (message.gateway !== 0) {
      obj.gateway = Math.round(message.gateway);
    }
    if (message.subnetMask !== 0) {
      obj.subnetMask = Math.round(message.subnetMask);
    }
    if (message.dns !== 0) {
      obj.dns = Math.round(message.dns);
    }
    return obj;
  },

  create<I extends Exact<DeepPartial<PBNetInfo>, I>>(base?: I): PBNetInfo {
    return PBNetInfo.fromPartial(base ?? ({} as any));
  },
  fromPartial<I extends Exact<DeepPartial<PBNetInfo>, I>>(object: I): PBNetInfo {
    const message = createBasePBNetInfo();
    message.macAddr = object.macAddr ?? new Uint8Array(0);
    message.useDhcp = object.useDhcp ?? false;
    message.ip = object.ip ?? 0;
    message.gateway = object.gateway ?? 0;
    message.subnetMask = object.subnetMask ?? 0;
    message.dns = object.dns ?? 0;
    return message;
  },
};

function createBasePBServerInfo(): PBServerInfo {
  return { hostname: "", port: 0 };
}

export const PBServerInfo = {
  encode(message: PBServerInfo, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
    if (message.hostname !== "") {
      writer.uint32(10).string(message.hostname);
    }
    if (message.port !== 0) {
      writer.uint32(16).uint32(message.port);
    }
    return writer;
  },

  decode(input: _m0.Reader | Uint8Array, length?: number): PBServerInfo {
    const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = createBasePBServerInfo();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          if (tag !== 10) {
            break;
          }

          message.hostname = reader.string();
          continue;
        case 2:
          if (tag !== 16) {
            break;
          }

          message.port = reader.uint32();
          continue;
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skipType(tag & 7);
    }
    return message;
  },

  fromJSON(object: any): PBServerInfo {
    return {
      hostname: isSet(object.hostname) ? globalThis.String(object.hostname) : "",
      port: isSet(object.port) ? globalThis.Number(object.port) : 0,
    };
  },

  toJSON(message: PBServerInfo): unknown {
    const obj: any = {};
    if (message.hostname !== "") {
      obj.hostname = message.hostname;
    }
    if (message.port !== 0) {
      obj.port = Math.round(message.port);
    }
    return obj;
  },

  create<I extends Exact<DeepPartial<PBServerInfo>, I>>(base?: I): PBServerInfo {
    return PBServerInfo.fromPartial(base ?? ({} as any));
  },
  fromPartial<I extends Exact<DeepPartial<PBServerInfo>, I>>(object: I): PBServerInfo {
    const message = createBasePBServerInfo();
    message.hostname = object.hostname ?? "";
    message.port = object.port ?? 0;
    return message;
  },
};

function createBasePBTerninalConfigration(): PBTerninalConfigration {
  return { deviceInfo: undefined, netInfo: undefined, serverInfo: undefined };
}

export const PBTerninalConfigration = {
  encode(message: PBTerninalConfigration, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
    if (message.deviceInfo !== undefined) {
      PBDeviceInfo.encode(message.deviceInfo, writer.uint32(10).fork()).ldelim();
    }
    if (message.netInfo !== undefined) {
      PBNetInfo.encode(message.netInfo, writer.uint32(18).fork()).ldelim();
    }
    if (message.serverInfo !== undefined) {
      PBServerInfo.encode(message.serverInfo, writer.uint32(26).fork()).ldelim();
    }
    return writer;
  },

  decode(input: _m0.Reader | Uint8Array, length?: number): PBTerninalConfigration {
    const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = createBasePBTerninalConfigration();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          if (tag !== 10) {
            break;
          }

          message.deviceInfo = PBDeviceInfo.decode(reader, reader.uint32());
          continue;
        case 2:
          if (tag !== 18) {
            break;
          }

          message.netInfo = PBNetInfo.decode(reader, reader.uint32());
          continue;
        case 3:
          if (tag !== 26) {
            break;
          }

          message.serverInfo = PBServerInfo.decode(reader, reader.uint32());
          continue;
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skipType(tag & 7);
    }
    return message;
  },

  fromJSON(object: any): PBTerninalConfigration {
    return {
      deviceInfo: isSet(object.deviceInfo) ? PBDeviceInfo.fromJSON(object.deviceInfo) : undefined,
      netInfo: isSet(object.netInfo) ? PBNetInfo.fromJSON(object.netInfo) : undefined,
      serverInfo: isSet(object.serverInfo) ? PBServerInfo.fromJSON(object.serverInfo) : undefined,
    };
  },

  toJSON(message: PBTerninalConfigration): unknown {
    const obj: any = {};
    if (message.deviceInfo !== undefined) {
      obj.deviceInfo = PBDeviceInfo.toJSON(message.deviceInfo);
    }
    if (message.netInfo !== undefined) {
      obj.netInfo = PBNetInfo.toJSON(message.netInfo);
    }
    if (message.serverInfo !== undefined) {
      obj.serverInfo = PBServerInfo.toJSON(message.serverInfo);
    }
    return obj;
  },

  create<I extends Exact<DeepPartial<PBTerninalConfigration>, I>>(base?: I): PBTerninalConfigration {
    return PBTerninalConfigration.fromPartial(base ?? ({} as any));
  },
  fromPartial<I extends Exact<DeepPartial<PBTerninalConfigration>, I>>(object: I): PBTerninalConfigration {
    const message = createBasePBTerninalConfigration();
    message.deviceInfo = (object.deviceInfo !== undefined && object.deviceInfo !== null)
      ? PBDeviceInfo.fromPartial(object.deviceInfo)
      : undefined;
    message.netInfo = (object.netInfo !== undefined && object.netInfo !== null)
      ? PBNetInfo.fromPartial(object.netInfo)
      : undefined;
    message.serverInfo = (object.serverInfo !== undefined && object.serverInfo !== null)
      ? PBServerInfo.fromPartial(object.serverInfo)
      : undefined;
    return message;
  },
};

function bytesFromBase64(b64: string): Uint8Array {
  if (globalThis.Buffer) {
    return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
  } else {
    const bin = globalThis.atob(b64);
    const arr = new Uint8Array(bin.length);
    for (let i = 0; i < bin.length; ++i) {
      arr[i] = bin.charCodeAt(i);
    }
    return arr;
  }
}

function base64FromBytes(arr: Uint8Array): string {
  if (globalThis.Buffer) {
    return globalThis.Buffer.from(arr).toString("base64");
  } else {
    const bin: string[] = [];
    arr.forEach((byte) => {
      bin.push(globalThis.String.fromCharCode(byte));
    });
    return globalThis.btoa(bin.join(""));
  }
}

type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;

export type DeepPartial<T> = T extends Builtin ? T
  : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>>
  : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
  : T extends {} ? { [K in keyof T]?: DeepPartial<T[K]> }
  : Partial<T>;

type KeysOfUnion<T> = T extends T ? keyof T : never;
export type Exact<P, I extends P> = P extends Builtin ? P
  : P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };

function isSet(value: any): boolean {
  return value !== null && value !== undefined;
}
